package com.ysq.nfd.config;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.apache.log4j.Logger;

import com.ysq.nfd.util.CommonUtil;

/**
 * 加载 base config
 * @author admin
 *
 */
public final class BaseConfigInfo {
	static Logger logger = CommonUtil.getLogger(BaseConfigInfo.class);
	
	/**************************************** 配置参数 ****************************************/
	
	public static String net_url;
	public static String save_path;
	static{
		try {
			initAllConfig(ConfigFilePath.configBaseDir + ConfigFilePath.baseConfig);
		} catch(Exception e) {
			logger.error("load properties file error ... ", e);
		}
	}
	
	/**
	 * 初始化所有config
	 * @param configfile
	 * @throws ConfigurationException
	 */
	public static void initAllConfig(String configfile) throws ConfigurationException {
		XMLConfiguration config = new XMLConfiguration(configfile);
		config.setExpressionEngine(new XPathExpressionEngine());
		loadConfig(config);
	}
	
	private static void loadConfig(XMLConfiguration config) {
		
		/** ========== socket ========== **/
		
		String key = "net_url";
		if(config.containsKey(key)){
			net_url = config.getString(key);
		}
		
		key = "save_path";
		if(config.containsKey(key)){
			save_path = config.getString(key);
		}
		
		
	}
	
	
	
	public static void main(String[] args) {
		
		System.out.println("rootDir : " + net_url);
		
		
	}

}
